﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;

namespace custom
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //初始化服务按钮
            ControlGenerator buttonGenerator = new ControlGenerator(this,tabControl1);
            buttonGenerator.genner();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            InputForm inputForm = new InputForm();
            if (inputForm.ShowDialog() == DialogResult.OK)
            {
                string name = inputForm.name;
                string path = inputForm.path;
                string command = inputForm.command;
                string close = inputForm.close;
                MessageBox.Show($"Name: {name}\npath: {path}\ncommand: {command}\nclose: {close}");
            }
            // 清除所有按钮
            List<Control> controlsToDelete = new List<Control>();
            foreach (Control control in this.Controls)
            {
                if (control.Name != "addBtn" && control.Name != "pictureBox1" && control.Name != "label1" && control.Name != "button9" && control.Name != "tabControl1")
                {
                    controlsToDelete.Add(control);
                }
            }
            foreach (Control control in controlsToDelete)
            {
                this.Controls.Remove(control);
                control.Dispose();
            }
            //清除所有tabPage
            //List<TabPage> tabPageToDelete = new List<TabPage>();
            //foreach (TabPage tabPage in tabControl1.TabPages)
            //{
            //    tabPageToDelete.Add(tabPage);
            //}
            tabControl1.TabPages.Clear();
            ControlGenerator buttonGenerator = new ControlGenerator(this, tabControl1);
            buttonGenerator.genner();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            MessageBox.Show("打开conf.ini文件\n按照模板修改对应服务的文件路径和执行命令\n", "使用帮助");
        }
    }
}
